package com.yunhai.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.core.controller.BaseController;
import com.yunhai.common.core.domain.AjaxResult;
import com.yunhai.common.core.page.TableDataInfo;
import com.yunhai.system.domain.WorkJob;
import com.yunhai.system.service.WorkJobService;
import org.apache.commons.collections.MapUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 产品列表
 *
 * @author jxj
 * @since 2021-01-09 17:53:32
 */
@RestController
@RequestMapping("/api/workJob")
public class WorkJobController extends BaseController {
    @Resource
    private WorkJobService workJobService;

    /**
     * 招聘列表
     *
     * @param param
     * @return
     */
    @PostMapping("list")
    public TableDataInfo list(@RequestBody Map<String, Object> param) {
        Long page = MapUtils.getLong(param, "page", 1L);
        Long limit = MapUtils.getLong(param, "limit", 10L);
        QueryWrapper<WorkJob> workJobQueryWrapper = new QueryWrapper<>();
        workJobQueryWrapper.orderByDesc("create_time");
        Page<WorkJob> pageResult = workJobService.page(new Page<>(page, limit), workJobQueryWrapper);
        return new TableDataInfo(pageResult.getRecords(),(int)pageResult.getTotal());
    }

    /**
     * 招聘列表
     *
     * @param id
     * @return
     */
    @GetMapping("info")
    public AjaxResult info(String id) {
        WorkJob workJob = workJobService.getById(id);
        if (null == workJob) {
            return AjaxResult.error("信息不存在");
        }

        return AjaxResult.success(workJob);
    }



}
